package ngat.oss.simulation.test;

import ngat.phase2.*;
import ngat.oss.simulation.*;
import java.io.*;
import ngat.util.*;
import ngat.astrometry.*;

/** Test - create Phase2ModelGenerator, configure model and dump.*/

public class Phase2GenDump {

    public static void main(String args[]) {

	final long TIMESTEP = 10*60*1000L;

	try {
	    
	    ConfigurationProperties cfg = CommandTokenizer.use("--").parse(args);
	    
	    File modelFile = new File(cfg.getProperty("model"));
	    ConfigurationProperties model = new ConfigurationProperties();
	    model.load(new FileInputStream(modelFile));

	    Site site = new Site(cfg.getProperty("site"),
				 Math.toRadians(cfg.getDoubleValue("lat")), 
				 Math.toRadians(cfg.getDoubleValue("long")));
	    
	    long eot = (ScheduleSimulator.sdf.parse(cfg.getProperty("eot"))).getTime();

	    BasicExecutionTimingModel exec = new BasicExecutionTimingModel(site, null);

	    File bxf = new File(cfg.getProperty("exec")); // exec model properties
	    PropertiesConfigurator.use(bxf).configure(exec);
	    exec.setExternalTimeConstraint(eot, "TEST_END");
	    BasicTimingConstraintWindowCalculator tcwc = new BasicTimingConstraintWindowCalculator(exec,  TIMESTEP);
	   
	    Phase2ModelGenerator gen = new Phase2ModelGenerator();
	    
	    Phase2ModelGeneratorParams params = gen.createModelParams(model);

	    gen.createPhase2Model(params, exec, tcwc);

	    File dumpFile = new File(cfg.getProperty("dump"));
	    gen.dumpPhase2Model(dumpFile);
	    
	} catch (Exception e) { 
	    e.printStackTrace();
	    System.err.println("Usage: Phase2GenDump --site <site-name> --lat <lat-deg> --long <e-long-deg) "+
			       "--eot <yyyy-MM-dd HH:mm:ss> --model <model-defn-file> --exec <exec-cfg-file> --dump <file.odb>");
	    
	}
    }
}
